package com.mall.advertising.controller;

import java.util.List;


import com.mall.advertising.domain.TAdvertising;
import com.mall.advertising.domain.dto.TAdvertisingDto;
import com.mall.advertising.service.ITAdvertisingService;
import com.mall.advertising.utils.OssUtil;
import com.mall.common.core.domain.Result;
import com.mall.common.core.web.controller.BaseController;
import com.mall.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


/**
 * 广告列表Controller
 *
 * @date 2025-02-14
 */
@RestController
@RequestMapping("/advertising")
@CrossOrigin
public class TAdvertisingController extends BaseController
{
    @Autowired
    private ITAdvertisingService tAdvertisingService;
    @Autowired
    private OssUtil ossUtil;

    /**
     * 查询广告列表列表
     */

    @GetMapping("/list")
    public  Result list(TAdvertising tAdvertising)
    {
        startPage();
        List<TAdvertising> list = tAdvertisingService.selectTAdvertisingList(tAdvertising);
        return getDataTable(list);
    }

    /**
     * 获取广告列表详细信息
     */

    @GetMapping(value = "/{advertisingId}")
    public Result getInfo(@PathVariable("advertisingId") Long advertisingId)
    {
        return Result.success(tAdvertisingService.selectTAdvertisingByAdvertisingId(advertisingId));
    }

    /**
     * 新增广告列表
     */


    @PostMapping
    public Result add(@RequestBody TAdvertisingDto tAdvertisingDto)
    {
       tAdvertisingService.insertTAdvertising(tAdvertisingDto);
       return Result.success();
    }

    /**
     * 修改广告列表
     */

    @PutMapping
    public Result edit(@RequestBody TAdvertisingDto tAdvertisingDto)
    {
        tAdvertisingService.updateTAdvertising(tAdvertisingDto);
        return Result.success();
    }



    /**
     * 删除广告列表
     */

	@DeleteMapping("/{advertisingIds}")
    public Result remove(@PathVariable Long[] advertisingIds)
    {
        return toAjax(tAdvertisingService.deleteTAdvertisingByAdvertisingIds(advertisingIds));
    }
    /**
     * 图片上传
     */
    @PostMapping("/upload")
    public Result<String> uploadFile(MultipartFile file){
        String ossFilePath = ossUtil.uploadMultipartFile(file);
        return Result.success(ossFilePath);
    }

    /**
     * 上线  下线
     */
    @GetMapping("/updateStatue/{advertisingId}")
    public Result updateStatue(@PathVariable Integer advertisingId){
        tAdvertisingService.updateStatue(advertisingId);
        return Result.success();
    }


}
